import {parseTime} from "@/utils/timeUtils";
import { useLogListStore } from '@/data/stores/logList'
import {getDutyInfo} from "@/data/service/dutyService";

const logListStore = useLogListStore()

let count = 0

const dutyNumMap = new Map<string,number>()
const jobMap = new Map<number, number>()

const versionMap = new Map<number, number>()
const typeMap = new Map<number,number>()

const hourMap = new Map<number, number>()
const dateMap = new Map<string, number>()

function doAnalysis(){
    const length = logListStore.getLength()
    const logList = logListStore.getLogList(0, length)

    dutyNumMap.clear()
    jobMap.clear()
    versionMap.clear()
    typeMap.clear()
    hourMap.clear()
    dateMap.clear()

    count = logListStore.index

    for (const log of logList) {
        dutyNumMap.set(log.duty, (dutyNumMap.get(log.duty)||0) + 1)
        jobMap.set(log.job, (jobMap.get(log.job)||0) + 1)

        const dutyInfo = getDutyInfo(log.duty)
        versionMap.set(dutyInfo.ver, (versionMap.get(dutyInfo.ver)||0) + 1)
        typeMap.set(dutyInfo.type, (typeMap.get(dutyInfo.type)||0) + 1)

        const time = new Date(log.date)
        const timeKey = parseTime(time.getTime(), '{y}-{m}-{d}')
        hourMap.set(time.getHours(), (hourMap.get(time.getHours())||0) + 1)
        dateMap.set(timeKey!, (dateMap.get(timeKey!)||0) + 1)

    }
}

export {doAnalysis, count, dutyNumMap, jobMap, versionMap, typeMap, hourMap, dateMap}
